<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/1/4
  Time: 14:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>添加商品</title>
    <style>
        .main {
            border: 2px solid cornflowerblue;
        }

        .main_msg {
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            margin-bottom: 20px;
        }

        .black_text {
            width: 100px;
            font-size: 16px;
            color: black;
            font-weight: bold;
        }

        .black_text + td {
            padding: 2px;
        }

        table, tr, td {
            border: 1px solid rgb(152, 194, 193);
            text-align: center;
        }

        td {
            padding: 9px;
        }

        table {
            margin: auto;
            width: 650px;
        }

        .main_msg_detail span {
            padding: 10px;
        }

        button {
            width: 100px;
            height: 33px;
        }

        .text_input {
            width: 100%;
            height: 27px;
        }

        select {
            width: 100%;
            height: 27px;
        }

        textarea {
            resize: none;
            height: 80px;
            width: 100%;
        }

        .number_input {
            width: 80%;
            height: 27px;
            float: left;
        }

    </style>
</head>
<body>
<script src="${pageContext.request.contextPath}/js/jquery-3.5.1.min.js"></script>
<div style="width: 760px">
    <%@ include file="../common/header.jsp" %>

    <div class="main">
        <div style="margin: 10px 20px">
            <img src="../img/product.gif" alt="商品">
        </div>
        <div class="main_msg">
            <div style="margin-bottom: 10px;color: cornflowerblue;font-size: 22px"><b>新增商品</b></div>
        </div>

        <form action="${pageContext.request.contextPath}/pro/add" method="post">
            <table cellspacing="0" cellpadding="12">

                <tr>
                    <td class="black_text">商品名称:</td>
                    <td colspan="3">
                        <input type="text" class="text_input" name="proname">
                    </td>
                </tr>

                <tr>
                    <td class="black_text">所属大类:</td>
                    <td colspan="3">
                        <select id="cateselect" name="catenum">
                            <c:forEach items="${cates}" var="cate">
                                <option value="${cate.catenum}">${cate.catename}</option>
                            </c:forEach>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="black_text">所属子类:</td>
                    <td colspan="1">
                        <select id="subcateselect" name="subcatenum">
                            <c:forEach items="${subcates}" var="subcate">
                                <option value="${subcate.subcatenum}">${subcate.subcatename}</option>
                            </c:forEach>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="black_text">出版/发行商:</td>
                    <td colspan="3">
                        <input type="text" class="text_input" name="propublisher">
                    </td>
                </tr>
                <tr>
                    <td class="black_text">作储/演员:</td>
                    <td colspan="3">
                        <input type="text" class="text_input" name="proauth">
                    </td>
                </tr>
                <tr>
                    <td class="black_text">商品猫述:</td>
                    <td colspan="3">
                    <textarea name="prodes">

                    </textarea>

                    </td>
                </tr>
                <tr>
                    <td class="black_text">原价:</td>
                    <td colspan="3">
                        <input type="number" class="number_input" name="proprice">
                        元
                    </td>
                </tr>
                <tr>
                    <td class="black_text">现价:</td>
                    <td colspan="3">
                        <input type="number" class="number_input" name="prodisprice">
                        元
                    </td>
                </tr>
                <tr>
                    <td class="black_text">是否打折:</td>
                    <td colspan="3">
                        <label for="t"><input id="t" type="radio" value="t" name="pridiscount"> 是</label>
                        <label for="f"><input id="f" type="radio" value="f" name="pridiscount"> 否</label>
                    </td>
                </tr>
                <tr>
                    <td class="black_text">重点推荐:</td>
                    <td colspan="3">
                        <label for="tj"><input id="tj" type="radio" value="t" name="prorecom"> 是</label>
                        <label for="tj2"><input id="tj2" type="radio" value="f" name="prorecom"> 否</label>
                    </td>
                </tr>
                <tr>
                    <td class="black_text">小图片名称:</td>
                    <td colspan="3">
                        <input type="text" class="text_input" name="prosimgname">
                    </td>
                </tr>
                <tr>
                    <td class="black_text">大图片名称:</td>
                    <td colspan="3">
                        <input type="text" class="text_input" name="prolimgname">
                    </td>
                </tr>
                <tr>
                    <td class="black_text">库存量:</td>
                    <td colspan="3">
                        <input type="number" class="number_input" min="0" name="prostock">
                    </td>
                </tr>
                <tr>
                    <td class="black_text">销售量:</td>
                    <td colspan="3">
                        <input type="number" class="number_input" min="0" name="prosalenum">
                    </td>
                </tr>
                <tr>
                    <td class="black_text">访问量:</td>
                    <td colspan="3">
                        <input type="number" class="number_input" min="0" name="proaccessnum">
                    </td>
                </tr>
                <tr>
                    <td class="black_text">重量:</td>
                    <td colspan="3">
                        <input type="number" class="number_input" min="0" name="proweight"> 公斤
                    </td>
                </tr>

            </table>
        <div style="text-align: center;font-size: 22px;margin: 10px auto">
            <button>添加商品</button>
        </div>
        </form>

    </div>
    <%@ include file="../common/footer.jsp" %>
</div>
</body>
<script>
    $(function () {
        //当大类的值发生改变的时候，发送一次请求
        $("#cateselect").change(function () {
            var catenum = this.value;
            $.ajax({
                url: "${pageContext.request.contextPath}/pro/subcatelist",
                data: {
                    "catenum": catenum
                },
                success: function (obj) {
                    //拿到数据之后就删除掉子类下面的option元素
                    $("#subcateselect").empty("option");
                    console.log(obj)
                    var list = obj;

                    for (var i = 0; i < list.length; i++) {
                        var subcatename = list[i].subcatename;
                        var subcatenum = list[i].subcatenum;
                        $("#subcateselect").append("<option value=" + subcatenum + ">" + subcatename + "</option>")
                    }
                }
            })
        })
    })
</script>
</html>
